//--------------------------------------------------------------
version 18.0
clear all
set more off
set rmsg on
cap set scheme plotplain

* --------------------------------------------------------------
* Project root (robust to where the do-file is run from)
* --------------------------------------------------------------
local thisdo = c(filename)

* Fallback if c(filename) is empty (rare)
if "`thisdo'" == "" {
    global root "`c(pwd)'"
}
else {
    * Directory containing this do-file
    local dodir : dirname "`thisdo'"
    * Project root is parent of /dofile
    local root  : dirname "`dodir'"
    global root "`root'"
}

* If someone runs from inside /dofile (extra safety)
if substr("${root}", -6, 6) == "dofile" {
    global root = substr("${root}", 1, length("${root}")-6)
}

* --------------------------------------------------------------
* Paths (relative; no machine-specific paths)
* --------------------------------------------------------------
global data   "${root}/data"
global do     "${root}/dofile"
global out    "${root}/output"
global table  "${out}/tables"
global graph  "${out}/graphs"

cap mkdir "${out}"
cap mkdir "${table}"
cap mkdir "${graph}"

*--------------------------------------------------------------
* Log (store in /output so users always have write permission)
*--------------------------------------------------------------
cap log close _all
capture noisily log using "${out}/replication_analysis.log", text replace name(rep)

*--------------------------------------------------------------
* Dependencies (install only if missing)
*--------------------------------------------------------------
cap which outreg2
if _rc ssc install outreg2, replace
cap which coefplot
if _rc ssc install coefplot, replace
cap which estout
if _rc ssc install estout, replace
cap which medeff
if _rc ssc install medeff, replace

*--------------------------------------------------------------
* Data
* Note: `finaldata.dta` excludes geolocation for data protection.
*--------------------------------------------------------------
use "${data}/finaldata.dta", clear

//--------------------------------------------------------------
// Globals: controls, outcomes, etc.
//--------------------------------------------------------------
global controls female age ib1.reli_new ib1.ethnicity_new ib4.educ_new vote_intent polint gendemoc_pre
global medcontrols female age reli_new ethnicity_new educ_new vote_intent polint gendemoc_pre

// Unbalanced sets used in robustness
global cvars female ib4.reli_new ib1.ethnicity_new vote_intent gendemoc_pre
global pcvars female  gendemoc_pre

// Pre-treatment (for balance plots)
global pretreat female age safe_community polint ib1.reli_new ib1.ethnicity_new ib4.educ_new gendemoc_pre terror_exp vote_intent 

// Outcomes
global outcomes1 terrorism_regime gendemoc_post auth_support democ_policy donation demonstrat_democracy  
global outcomes2 priority_cohesion priority_job priority_weapon post_security
global outc_video video_info video_vicarious video_social
global autho authoritarianism_*

* Standardizing outcomes (min 0 and max 1)

foreach v of varlist $outcomes1 $outcomes2 $outc_video $autho {
    qui summ `v'
    gen z`v' = (`v' - r(min)) / (r(max) - r(min))
}


// Standardised Outcomes
global zoutcome1 zterrorism_regime zgendemoc_post zauth_support zdemoc_policy zdonation zdemonstrat_democracy 
global zoutcome2 zpriority_cohesion zpriority_job zpriority_weapon zpost_security
global zoutc_video zvideo_info zvideo_vicarious zvideo_social
global zautho zauthoritarianism_*

* Treatments for balance test
global treatments rights Bftreat gentreat alltreat

//--------------------------------------------------------------
// TABLE 1 — Descriptive table: main outcomes
//--------------------------------------------------------------
* ensure estout
cap which esttab
if _rc ssc install estout, replace

* labels (if needed)
label var zterrorism_regime        "Democratic advantage"
label var zgendemoc_post           "Democratic preference"
label var zauth_support            "Rejection of authoritarian alternatives"
label var zdemoc_policy            "Vote for democratic candidate"
label var zdonation                "Donation to Pro-democratic NGO"
label var zdemonstrat_democracy    "Pro-democratic protest"

* summaries
estimates clear
qui estpost summarize ///
    zterrorism_regime zgendemoc_post zauth_support zdemoc_policy zdonation zdemonstrat_democracy, detail

* Wider line to avoid wrapping in Results
set linesize 120

* Pretty Results-window table (no LaTeX)
esttab, nomtitles nonumber noobs label ///
    cells("count(fmt(%9.0gc)) mean(fmt(3)) sd(fmt(3)) min(fmt(0)) max(fmt(0))") ///
    collabels("Obs" "Mean" "Std." "Min" "Max") ///
    alignment(c) varwidth(32) compress

	* ---------------- SAVE AS CSV (output/tables) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab using "`tdir'Table1_descriptives_main_outcomes.csv", replace ///
    nomtitles nonumber noobs label ///
    cells("count(fmt(%9.0gc)) mean(fmt(3)) sd(fmt(3)) min(fmt(0)) max(fmt(0))") ///
    collabels("Obs" "Mean" "Std." "Min" "Max") ///
    alignment(c) varwidth(32) ///
    plain

	
//--------------------------------------------------------------
// TABLE 2 — Main pooled treatment (All vs Placebo)
//--------------------------------------------------------------
capture erase "${table}/pooled.xls"
capture erase "${table}/pooled.rtf"
estimates clear
cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $zoutcome1 {
    // Run model
   qui reg `k' i.alltreat $controls 

    // Control-group summary stats
    quietly summ `k' if alltreat==0
    local m   = r(mean)
    local min = r(min)
    local max = r(max)
    
    // Short titles for Results window
    local short_title ""
    if "`k'" == "zterrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "zgendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "zauth_support"             local short_title "Reject auth."
    if "`k'" == "zdemoc_policy"             local short_title "Vote dem. cand."
    if "`k'" == "zdonation"                 local short_title "Donate NGO"
    if "`k'" == "zdemonstrat_democracy"     local short_title "Attend protest"

    // Add footer stats
     qui estadd scalar cmean = `m'
     qui estadd scalar cmin  = `min'
     qui estadd scalar cmax  = `max'
     qui estadd local  pretreat "Yes"

    eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* --------- PRINT TO RESULTS WINDOW (compressed to fit) ----------
esttab `models', ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    mtitle ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "Min" "Max")) ///
    compress

* --------- CSV (portable) ----------
esttab `models' using "`tdir'pooled_treatment.csv", replace ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    mtitle ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "Min" "Max")) ///
    plain

*-----------------------------------------------------------------------------------
* TABLE 3 — By treatment arm (1=Civic rights, 2=General, 3=Burkina). Base=0 Placebo
* Prints to Results window (replicable via log)
*-----------------------------------------------------------------------------------
capture erase "${table}/cate_treat.xls"
capture erase "${table}/cate_treat.rtf"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $zoutcome1 {

    *-----------------------
    * Run model (baseline=0)
    *-----------------------
  qui  reg `k' ib0.treat $controls 

    *------------------------------------------
    * Control-group stats on estimation sample
    *------------------------------------------
    quietly summarize `k' if e(sample) & treat==0
    local m = r(mean)

    *-------------------------
    * Short column titles (fit)
    *-------------------------
    local short_title ""
    if "`k'" == "zterrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "zgendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "zauth_support"             local short_title "Reject auth."
    if "`k'" == "zdemoc_policy"             local short_title "Vote dem. cand."
    if "`k'" == "zdonation"                 local short_title "Donate NGO"
    if "`k'" == "zdemonstrat_democracy"     local short_title "Attend protest"

    *---------------------
    * Hypothesis tests
    *---------------------
    * H1: T1 = T2 + T3  (Civic rights vs terrorism (T2+T3))
     qui test _b[1.treat] = _b[2.treat] + _b[3.treat]
    local pval  = r(p)

    * H2: T2 = T3  (General vs Burkina Faso)
     qui test _b[2.treat] = _b[3.treat]
    local pval1 = r(p)

    *----------------------------------------
    * Add scalars for footer (to esttab stats)
    *----------------------------------------
     qui estadd scalar cmean = `m'
     qui estadd scalar p_civic_23 = `pval'
     qui estadd scalar p_2v3      = `pval1'
     qui estadd local  pretreat "Yes"

    eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

*-------------------------------
* PRINT to Results window
*-------------------------------
esttab `models', ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_civic_23 p_2v3, ///
          fmt(0 3 0 3 3 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" ///
                 "T1 vs (T2+T3) (p-val.)" "T2 vs T3 (p-val.)")) ///
    compress

* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'Table3_by_treatment_arm.csv", replace ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_civic_23 p_2v3, ///
          fmt(0 3 0 3 3 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" ///
                 "T1 vs (T2+T3) (p-val.)" "T2 vs T3 (p-val.)")) ///
    plain

//--------------------------------------------------------------
// TABLE 4 - Post-video manipulation (T2/T3 vs T1 reference)
//--------------------------------------------------------------
capture confirm var treat
if _rc==0 {
    cap drop treat_video
    recode treat (0=.) (1=0 "rights") (2=1 "general") (3=2 "burkina"), gen(treat_video)
    label var treat_video "Treatment (ref = rights)"
}
fre treat_video

capture erase "${table}/outc_screen.tex"
capture erase "${table}/outc_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $zoutc_video {

    * Run model with factor vars; base (0) = rights
 qui   reg `k' ib0.treat_video $controls 

    * Control-group mean on estimation sample only
    quietly summarize `k' if e(sample) & treat_video==0
    local m = r(mean)

    * Short, console-friendly column titles
    local short_title "`k'"
    if inlist("`k'","video_info","zvideo_info")              local short_title "Video info"
    if inlist("`k'","country_vision","zcountry_vision")      local short_title "Country vision"
    if inlist("`k'","video_share","zvideo_share","share_vid") local short_title "Video sharing"

    * Equality test: General vs Burkina Faso
    qui test _b[1.treat_video] = _b[2.treat_video]
    local pval = r(p)

    * Footer stats for esttab
    qui estadd scalar cmean = `m'
    qui estadd scalar p_g_vs_bf = `pval'
    qui estadd local  pretreat "Yes"

    eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* --------- PRINT to Results window (fits width) ----------
esttab `models', ///
    keep(1.treat_video 2.treat_video) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat_video "T2: General terrorism" ///
               2.treat_video "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_g_vs_bf, ///
          fmt(0 3 0 3 2) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "General vs Burkina (p-val.)")) ///
    compress

* ---------------- SAVE AS CSV (output/tables) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'Table4_postvideo_manipulation.csv", replace ///
    keep(1.treat_video 2.treat_video) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat_video "T2: General terrorism" ///
               2.treat_video "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_g_vs_bf, ///
          fmt(0 3 0 3 4) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "General vs Burkina (p-val.)")) ///
    plain
	
*--------------------------------
* Figure 4 — by lived experience (0/1)
*--------------------------------

foreach k of varlist $zoutcome1 {

    * Assign descriptive label for DV
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    * Binary interaction regression
  qui  reg `k' i.alltreat##i.terror_exp $controls 

    * Marginal effects by terrorism experience
   qui  margins, dydx(alltreat) at(terror_exp = (0(1)1)) 

    * Plot
    qui marginsplot, ///
        ylabel(-.15(.05).15) ///
        xlabel(, labsize(medium)) ///
        yline(0) ///
        xtitle("Terrorism experience", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

* Combine and export
graph combine $zoutcome1
graph save "${graph}/terror_exp.gph", replace 
graph export "${graph}/terror_exp.eps", replace 
graph export "${graph}/terror_exp.pdf", as(pdf) replace

*--------------------------------
*Figure 5 — by distance (0–200 km)
*--------------------------------

foreach k of varlist $zoutcome1 {

    * Assign descriptive label for DV
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    * Continuous interaction regression
 qui   reg `k' i.alltreat##c.km_to_id_B $controls 

    * Marginal effects by distance (0 to 200 km)
    qui margins, dydx(alltreat) at(km_to_id_B = (0(20)200))

    * Plot
    qui marginsplot, ///
        ylabel(-.15(.05).15) ///
        xlabel(, labsize(vsmall)) ///
        yline(0) ///
        xtitle("Distance to terrorist attacks (km)", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(medsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

* Combine and export
graph combine $zoutcome1
graph save "${graph}/distance.gph", replace 
graph export "${graph}/distance.eps", replace 
graph export "${graph}/distance.pdf", as(pdf) replace


//--------------------------------------------------------------
// APPENDIX TABLES 
//--------------------------------------------------------------

// In the main text, appendix tables and figures are numbered by section; in the online appendix, they are numbered consecutively in Arabic numerals. To aid cross-referencing, I report the main-text label first, followed in brackets by the corresponding online-appendix label: [main label (online appendix label)]
***--------------------------------
* Table E.1 (Table 5) — Attrition vs Assignment (LPM)
***--------------------------------
capture erase "${table}/attrited_screen.tex"
capture erase "${table}/attrited_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

* Model (1): No covariates
qui reg attrition ib0.treat 
eststo, title("No covariates")

* Model (2): With covariates
qui reg attrition ib0.treat $controls 
eststo, title("With covariates")

* Print to Results window (replicable via log)
esttab, ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05 ** 0.01) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2, fmt(0 3) labels("Observations" "R^2")) ///
    compress

* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab using "`tdir'TableE1_attrition_vs_assignment.csv", replace ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05 ** 0.01) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2, fmt(0 3) labels("Observations" "R^2")) ///
    plain

//--------------------------------------------------------------
//  Figure E1 (Figure 8): Balance plot (coefplot).
//--------------------------------------------------------------
estimates clear
foreach y of varlist $treatments {
    quietly reg `y' $pretreat 
    estimates store T0_`y'
}
coefplot T0_rights || T0_Bftreat || T0_gentreat || T0_alltreat, ///
    drop(_cons) xline(0, lpattern(solid)) byopts(row(1)) levels(99 95 90) ///
    bylabels("(A)" "(B)" "(C)" "(D)") nokey ///
    title("Balance test")
addplot 1: , b1title("right vs Placebo", size(small)) norescaling
addplot 2: , b1title("Burkina vs Placebo") norescaling
addplot 3: , b1title("General vs Placebo") norescaling
addplot 4: , b1title("All vs Placebo") norescaling

graph save   "${graph}/balance_demo.gph", replace
graph export "${graph}/balance_demo.eps", replace
graph export "${graph}/balance_demo.pdf", replace

//--------------------------------------------------------------
// Robustness: full specs, unbalanced covariates, weighted, etc.
//--------------------------------------------------------------
**--------------------------------
* Table F1 (Table 6): Treatment Effects — All Treatment vs Placebo (full results)
*--------------------------------
capture erase "${table}/fpooled_screen.tex"
capture erase "${table}/fpooled_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutcome1 {

    // Run model (base=0 Placebo); keep constant (standard OLS)
  qui  reg `k' ib0.alltreat $controls 

    // Control-group mean on estimation sample only
    quietly summarize `k' if e(sample) & alltreat==0
    local m = r(mean)

    // Short titles that fit the console
    local short_title ""
    if "`k'" == "zterrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "zgendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "zauth_support"             local short_title "Reject auth."
    if "`k'" == "zdemoc_policy"             local short_title "Vote dem. cand."
    if "`k'" == "zdonation"                 local short_title "Donate NGO"
    if "`k'" == "zdemonstrat_democracy"     local short_title "Attend protest"

    // Footer stats for esttab
qui    estadd scalar cmean = `m'
qui    estadd local  pretreat "Yes"

    // Store model
 qui   eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* ---------- PRINT to Results window (full results) ----------
esttab `models', ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    order(1.alltreat) ///
    coeflabels(1.alltreat "Pooled treatment") ///
    mtitle ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    compress
	
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableF1_pooled_treat_vs_placebo_full.csv", replace ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    order(1.alltreat) ///
    coeflabels(1.alltreat "Pooled treatment") ///
    mtitle ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    plain

**--------------------------------
* Table F2 (Table 7): Comparing Treatment Groups vs Placebo (full results)
**--------------------------------
capture erase "${table}/fcate_treat_screen.tex"
capture erase "${table}/fcate_treat_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $zoutcome1 {

    // Run model (base=0 Placebo)
  qui  reg `k' ib0.treat $controls 

    // Control-group mean on estimation sample
    quietly summarize `k' if e(sample) & treat==0
    local m = r(mean)

    // Short titles to fit console width
    local short_title ""
    if "`k'" == "zterrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "zgendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "zauth_support"             local short_title "Reject auth."
    if "`k'" == "zdemoc_policy"             local short_title "Vote dem. cand."
    if "`k'" == "zdonation"                 local short_title "Donate NGO"
    if "`k'" == "zdemonstrat_democracy"     local short_title "Attend protest"

    // Joint equality: T1 = T2 = T3  (correct multi-equality test)
    test (_b[1.treat] = _b[2.treat]) (_b[1.treat] = _b[3.treat])
    local p_all = r(p)

    // Footer stats
  qui  estadd scalar cmean   = `m'
  qui  estadd scalar p_all   = `p_all'
  qui  estadd local  pretreat "Yes"

    // Store model with short title
    eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* Print full results to Results window
* - Treatment rows first; covariates follow (labelled if var labels exist)
esttab `models', ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    order(1.treat 2.treat 3.treat) ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_all, ///
          fmt(0 3 0 3 4) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "All equal (p-val.)")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableF2_compare_treatments_vs_placebo_full.csv", replace ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    order(1.treat 2.treat 3.treat) ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_all, ///
          fmt(0 3 0 3 4) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "All equal (p-val.)")) ///
    plain

*-----------------------------
* Table G1(Table 8): Treatment Effects: All Treatment versus Placebo (Unbalanced pre-treatment)
*-----------------------------
//--------------------------------------------------------------
// Pooled: All treatment vs Placebo — with partial controls ($pcvars)
// Prints to Results window (replicable via log)
//--------------------------------------------------------------
capture erase "${table}/cpooled_screen.tex"
capture erase "${table}/cpooled_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $zoutcome1 {

    // OLS with base=0 (Placebo) and partial controls
  qui  reg `k' ib0.alltreat $pcvars 

    // Control Mean on the estimation sample only
    quietly summarize `k' if e(sample) & alltreat==0
    local m = r(mean)

    // Short titles to fit console width
    local short_title ""
    if "`k'" == "zterrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "zgendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "zauth_support"             local short_title "Reject auth."
    if "`k'" == "zdemoc_policy"             local short_title "Vote dem. cand."
    if "`k'" == "zdonation"                 local short_title "Donate NGO"
    if "`k'" == "zdemonstrat_democracy"     local short_title "Attend protest"

    // Footer stats for esttab
  qui  estadd scalar cmean = `m'
  qui  estadd local  pretreat "Yes"

  qui  eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* ------ PRINT to Results window (compact & accurate) ------
esttab `models', ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    mtitle ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableG1_pooled_unbalanced_pretreat.csv", replace ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    mtitle ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    plain

*-----------------------------
* Table G2(Table 9): Comparing Treatment Groups vs Placebo (Unbalanced pre-treatment)
*-----------------------------
capture erase "${table}/ccate_treat_screen.tex"
capture erase "${table}/ccate_treat_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $zoutcome1 {

    // OLS with placebo (0) as base; unbalanced controls
 qui   reg `k' ib0.treat $cvars 

    // Control Mean on estimation sample (placebo group only)
    quietly summarize `k' if e(sample) & treat==0
    local m = r(mean)

    // Short DV titles to fit console width
    local short_title ""
    if "`k'" == "zterrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "zgendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "zauth_support"             local short_title "Reject auth."
    if "`k'" == "zdemoc_policy"             local short_title "Vote dem. cand."
    if "`k'" == "zdonation"                 local short_title "Donate NGO"
    if "`k'" == "zdemonstrat_democracy"     local short_title "Attend protest"

    // Joint equality: T1 = T2 = T3
qui    test (_b[1.treat] = _b[2.treat]) (_b[1.treat] = _b[3.treat])
    local p_all = r(p)

    // Footer stats for esttab
 qui   estadd scalar cmean   = `m'
 qui   estadd scalar p_all   = `p_all'
  qui  estadd local  pretreat "Yes"

 qui   eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* --------- PRINT to Results window (treatment rows only) ----------
esttab `models', ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_all, ///
          fmt(0 3 0 3 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "All equal (p-val.)")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableG2_compare_treatments_unbalanced_pretreat.csv", replace ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_all, ///
          fmt(0 3 0 3 ) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "All equal (p-val.)")) ///
    plain
		
**--------------------------------
* Table G3 (Table 10): Comparing pooled terrorism and civic rights treatments
**--------------------------------
capture erase "${table}/cate_pooled_screen.tex"
capture erase "${table}/cate_pooled_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $zoutcome1 {

    // OLS with placebo as base (0)
qui    reg `k' ib0.terrorism_right $controls 

    // Control Mean on estimation sample (placebo group)
    quietly summarize `k' if e(sample) & terrorism_right==0
    local m = r(mean)

    // Short DV titles for console width
    local short_title ""
    if "`k'" == "zterrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "zgendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "zauth_support"             local short_title "Reject auth."
    if "`k'" == "zdemoc_policy"             local short_title "Vote dem. cand."
    if "`k'" == "zdonation"                 local short_title "Donate NGO"
    if "`k'" == "zdemonstrat_democracy"     local short_title "Attend protest"

    // Equality test: Civic rights = Terrorism (pooled)
 qui   test _b[1.terrorism_right] = _b[2.terrorism_right]
    local pval = r(p)

    // Footer stats for esttab
 qui   estadd scalar cmean = `m'
 qui   estadd scalar p_civic_vs_pooled = `pval'
 qui   estadd local  pretreat "Yes"

 qui   eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* --------- PRINT to Results window ----------
 esttab `models', ///
    keep(1.terrorism_right 2.terrorism_right) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.terrorism_right "T1: Civic rights" ///
               2.terrorism_right "T2/T3: Terrorism (pooled)") ///
    mtitle ///
    stats(N r2 pretreat cmean p_civic_vs_pooled, ///
          fmt(0 3 0 3 4) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "T1 vs T2/T3 (p-val.)")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableG3_civic_vs_terrorism_pooled.csv", replace ///
    keep(1.terrorism_right 2.terrorism_right) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.terrorism_right "T1: Civic rights" ///
               2.terrorism_right "T2/T3: Terrorism (pooled)") ///
    mtitle ///
    stats(N r2 pretreat cmean p_civic_vs_pooled, ///
          fmt(0 3 0 3 4) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "T1 vs T2/T3 (p-val.)")) ///
    plain
			
*-----------------------------
* Table H1 (Table 11): All Treatment vs Placebo (weighted)
*-----------------------------
capture erase "${table}/pooled_weight_screen.tex"
capture erase "${table}/pooled_weight_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $zoutcome1 {

    // OLS with placebo base (0) and analytic weights
   qui reg `k' ib0.alltreat $controls  [aweight=weight]

    // Control Mean on estimation sample control group, using the same weights
    quietly summarize `k' if e(sample) & alltreat==0 [aweight=weight]
    local m = r(mean)

    // Short, console-friendly DV titles
    local short_title ""
    if "`k'" == "zterrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "zgendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "zauth_support"             local short_title "Reject auth."
    if "`k'" == "zdemoc_policy"             local short_title "Vote dem. cand."
    if "`k'" == "zdonation"                 local short_title "Donate NGO"
    if "`k'" == "zdemonstrat_democracy"     local short_title "Attend protest"

    // Footer stats for esttab
 qui   estadd scalar cmean = `m'
 qui   estadd local  pretreat "Yes"

 qui   eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* --------- PRINT to Results window ----------
esttab `models', ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    mtitle ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableH1_pooled_weighted.csv", replace ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    mtitle ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    plain

*-----------------------------
* Table H2 (Table 12): Comparing Treatment Groups vs Placebo (weighted)
*-----------------------------
capture erase "${table}/cate_weight_screen.tex"
capture erase "${table}/cate_weight_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $zoutcome1 {

    // OLS with placebo (0) as base; analytic weights
  qui  reg `k' ib0.treat $controls  [aweight=weight]

    // Control Mean on estimation sample (placebo group) with same weights
    quietly summarize `k' if e(sample) & treat==0 [aweight=weight]
    local m = r(mean)

    // Short DV titles for console width
    local short_title ""
    if ("`k'"=="zterrorism_regime")        local short_title "Dem. adv."
    if ("`k'"=="zgendemoc_post")           local short_title "Dem. pref."
    if ("`k'"=="zauth_support")            local short_title "Reject auth."
    if ("`k'"=="zdemoc_policy")            local short_title "Vote dem. cand."
    if ("`k'"=="zdonation")                local short_title "Donate NGO"
    if ("`k'"=="zdemonstrat_democracy")    local short_title "Attend protest"

    // Joint equality: T1 = T2 = T3
    test (_b[1.treat] = _b[2.treat]) (_b[1.treat] = _b[3.treat])
    local p_all = r(p)

    // Footer stats for esttab
 qui   estadd scalar cmean   = `m'
 qui   estadd scalar p_all   = `p_all'
 qui   estadd local  pretreat "Yes"

    eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* --------- PRINT to Results window (treatment rows only) ----------
esttab `models', ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) ci level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_all, ///
          fmt(0 3 0 3 4) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "All equal (p-val.)")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableH2_compare_treatments_weighted.csv", replace ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean p_all, ///
          fmt(0 3 0 3 4) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "All equal (p-val.)")) ///
    plain

**--------------------------------					
// Main treatment effect, using original scales
**--------------------------------			

//--------------------------------------------------------------
// Table I1 (Table 13) — Main pooled treatment (All vs Placebo) 
//--------------------------------------------------------------
capture erase "${table}/pooled_OR_screen.tex"
capture erase "${table}/pooled_OR_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $outcomes1 {

    // OLS with placebo/base = 0
 qui   reg `k' ib0.alltreat $controls 

    // Control-group stats on the estimation sample only
    quietly summarize `k' if e(sample) & alltreat==0
    local m   = r(mean)
    local min = r(min)
    local max = r(max)

    // Short, console-friendly DV titles
    local short_title ""
    if "`k'" == "terrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "gendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "auth_support"             local short_title "Reject auth."
    if "`k'" == "democ_policy"             local short_title "Vote dem. cand."
    if "`k'" == "donation"                 local short_title "Donate NGO"
    if "`k'" == "demonstrat_democracy"     local short_title "Attend protest"

    // Footer stats for esttab
 qui   estadd scalar cmean = `m'
 qui   estadd scalar cmin  = `min'
 qui   estadd scalar cmax  = `max'
 qui   estadd local  covars "Yes"

    eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* ---------- PRINT to Results window (captured by your .log) ----------
esttab `models', ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatments vs. placebo") ///
    mtitle ///
    stats(N r2 covars cmean cmin cmax, ///
          fmt(0 3 0 3 0 0) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" "Min" "Max")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableI1_pooled_OR_main.csv", replace ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatments vs. placebo") ///
    mtitle ///
    stats(N r2 covars cmean cmin cmax, ///
          fmt(0 3 0 3 0 0) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" "Min" "Max")) ///
    plain

*-----------------------------------------------------------------------------------
* Table I2 (Table 14) — By treatment arm (1=Civic rights, 2=General, 3=Burkina) vs Placebo
*-----------------------------------------------------------------------------------
capture erase "${table}/cate_treat_OR_screen.tex"
capture erase "${table}/cate_treat_OR_screen.csv"
estimates clear

cap which esttab
if _rc ssc install estout, replace

local models

foreach k of varlist $outcomes1 {

    // OLS with placebo (0) as base; include full controls
  qui  reg `k' ib0.treat $controls 

    // Control-group stats on the estimation sample only
    quietly summarize `k' if e(sample) & treat==0
    local m   = r(mean)
    local cmin = r(min)
    local cmax = r(max)

    // Short DV titles (fits console)
    local short_title ""
    if "`k'" == "terrorism_regime"         local short_title "Dem. adv."
    if "`k'" == "gendemoc_post"            local short_title "Dem. pref."
    if "`k'" == "auth_support"             local short_title "Reject auth."
    if "`k'" == "democ_policy"             local short_title "Vote dem. cand."
    if "`k'" == "donation"                 local short_title "Donate NGO"
    if "`k'" == "demonstrat_democracy"     local short_title "Attend protest"

    // Hypothesis tests
    // H1: T1 = T2 + T3  (Civic vs combined terrorism)
  qui  test _b[1.treat] = _b[2.treat] + _b[3.treat]
    local p_civic_23 = r(p)

    // H2: T2 = T3  (General vs Burkina)
 qui   test _b[2.treat] = _b[3.treat]
    local p_2v3 = r(p)

    // Footer stats for esttab
 qui   estadd scalar cmean = `m'
 qui   estadd scalar cmin  = `cmin'
 qui   estadd scalar cmax  = `cmax'
 qui   estadd scalar p_civic_23 = `p_civic_23'
 qui   estadd scalar p_2v3      = `p_2v3'
 qui   estadd local  pretreat "Yes"

    eststo, title("`short_title'")
    local models `"`models' `e(name)'"'
}

* --------- PRINT to Results window (captured by .log) ----------
esttab `models', ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) ci level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean cmin cmax, ///
          fmt(0 3 0 3 0 0) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "Min" "Max" ///
                 "T1 = T2+T3 (p-val.)" "T2 = T3 (p-val.)")) ///
    compress

* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableI2_by_treatment_arm_OR.csv", replace ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) ci level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    mtitle ///
    stats(N r2 pretreat cmean cmin cmax, ///
           fmt(0 3 0 3 0 0) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "Min" "Max" ///
                 "T1 = T2+T3 (p-val.)" "T2 = T3 (p-val.)")) ///
    plain
	
*-----------------------------
* Table J1 (Table 15): Item-level analysis — Treatment vs Placebo
*-----------------------------
capture erase "${table}/cate_treat_autho_screen.tex"
capture erase "${table}/cate_treat_autho_screen.csv"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zautho {
    quietly reg `k' ib0.treat $controls

    quietly summarize `k' if e(sample) & treat==0
    local m    = r(mean)
    local cmin = r(min)
    local cmax = r(max)

    * Column titles
    local t ""
    if "`k'" == "zauthoritarianism_1" local t "Strong leader"
    if "`k'" == "zauthoritarianism_2" local t "Military rule"
    if "`k'" == "zauthoritarianism_3" local t "One-party rule"
    if "`k'" == "zauthoritarianism_4" local t "Sharia rule"
    if `"`t'"'== "" local t "`k'"

    * Footer stats
    qui estadd scalar cmean = `m'
    qui estadd scalar cmin  = `cmin'
    qui estadd scalar cmax  = `cmax'
    qui estadd local  covars "Yes"

    eststo
    local models  `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`t'""'
}

* ---------- PRINT ----------
esttab `models', ///
    mtitle(`mlabels') ///
    eqlabels(" ") /// ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) ci level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    stats(N r2 covars cmean cmin cmax, fmt(0 3 0 3 0 0) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" "Min" "Max")) ///
    compress

* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableJ1_itemlevel_authoritarianism.csv", replace ///
    mtitle(`mlabels') ///
    eqlabels(none) ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) ci level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    stats(N r2 covars cmean cmin cmax, ///
          fmt(0 3 0 3 0 0) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" "Min" "Max")) ///
    plain
	
////////////////////////////////////////////////////	
// Secondary outcomes
////////////////////////////////////////////////////	

**--------------------------------
* Table K1 (Table 16): All Treatment vs Placebo (secondary outcomes)
**--------------------------------
capture erase "${table}/pooled2_screen.tex"
capture erase "${table}/pooled2_screen.csv"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutcome2 {

  // Short DV titles (fits console)
    local short_title ""
    if "`k'"=="zpriority_cohesion" local short_title "Priority: Cohesion"
    if "`k'"=="zpriority_job"    local short_title "Priority: Jobs"
    if "`k'"=="zpriority_weapon"  local short_title "Priority: Weapons"
    if "`k'"=="zpost_security"  local short_title "Security Support"
    if `"`short_title'"'=="" {
        local short_title : variable label `k'
        if `"`short_title'"'=="" local short_title "`k'"
    }

    * OLS with placebo as base (0), full controls
   qui  reg `k' ib0.alltreat $controls 

    * Control mean on estimation sample (placebo group)
    quietly summarize `k' if e(sample) & alltreat==0
    local m = r(mean)

    * Footer stats for esttab
    qui estadd scalar cmean = `m'
    qui estadd local  pretreat "Yes"

    eststo
    local models `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`short_title'""'
}

* --------- PRINT to Results window ----------
esttab `models', ///
    mtitle(`mlabels') ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableK1_secondary_pooled_treat_vs_placebo.csv", replace ///
    mtitle(`mlabels') ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    plain

*------------------------------------
*Table K2 (Table 17): Comparing Treatment Groups versus Placebo 
*------------------------------------
capture erase "${table}/cate_treat2_screen.tex"
capture erase "${table}/cate_treat2_screen.csv"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutcome2 {

  // Short DV titles (fits console)
    local short_title ""
    if "`k'"=="zpriority_cohesion" local short_title "Priority: Cohesion"
    if "`k'"=="zpriority_job"    local short_title "Priority: Jobs"
    if "`k'"=="zpriority_weapon"  local short_title "Priority: Weapons"
    if "`k'"=="zpost_security"  local short_title "Security Support"
    if `"`short_title'"'=="" {
        local short_title : variable label `k'
        if `"`short_title'"'=="" local short_title "`k'"
    }

    * OLS with placebo (0) as base; full controls
    qui reg `k' ib0.treat $controls 

    * Control Mean using estimation-sample placebo group
    quietly summarize `k' if e(sample) & treat==0
    local m = r(mean)

    * Joint equality: T1 = T2 = T3  (correct syntax)
    qui test (_b[1.treat] = _b[2.treat]) (_b[1.treat] = _b[3.treat])
    local p_all = r(p)

    * Footer stats for esttab
    qui estadd scalar cmean   = `m'
    qui estadd scalar p_all   = `p_all'
    qui estadd local  pretreat "Yes"

    eststo
    local models  `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`short_title'""'
}

* --------- PRINT to Results window (captured in .log) ----------
esttab `models', ///
    mtitle(`mlabels') ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    stats(N r2 pretreat cmean p_all, ///
          fmt(0 3 0 3 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "All equal (p-val.)")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableK2_secondary_compare_treatments_vs_placebo.csv", replace ///
    mtitle(`mlabels') ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    stats(N r2 pretreat cmean p_all, ///
          fmt(0 3 0 3 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean" "All equal (p-val.)")) ///
    plain

//////////////////////////////////////////////////////	
// Constant observations across outcomes
//////////////////////////////////////////////////////
*------------------------------
** Table L1 (Table 18): Treatment Effects: All Treatment versus Placebo
*-------------------------------
gen missing = 0
replace missing=1 if zterrorism_regime!=. & zgendemoc_post!=. & zauth_support!=. & zdemoc_policy!=. & zdonation!=. & zdemonstrat_democracy!=. & female!=. & age!=.& reli_new!=. & ethnicity_new!=. & educ_new!=. & vote_intent!=. & polint!=. & gendemoc_pre!=.

capture erase "${table}/n_pooled_screen.tex"
capture erase "${table}/n_pooled_screen.csv"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutcome1 {

    // Short, readable column title (custom map -> var label -> var name)
    local short_title ""
    if ("`k'"=="zterrorism_regime")         local short_title "Dem. adv."
    if ("`k'"=="zgendemoc_post")            local short_title "Dem. pref."
    if ("`k'"=="zauth_support")             local short_title "Reject auth."
    if ("`k'"=="zdemoc_policy")             local short_title "Vote dem. cand."
    if ("`k'"=="zdonation")                 local short_title "Donate NGO"
    if ("`k'"=="zdemonstrat_democracy")     local short_title "Attend protest"
    if `"`short_title'"'=="" {
        local short_title : variable label `k'
        if `"`short_title'"'=="" local short_title "`k'"
    }

    // OLS with placebo as base (0), restricted sample
    reg `k' ib0.alltreat $controls if missing==1 

    // Control Mean from the SAME estimation sample control group
    quietly summarize `k' if e(sample) & alltreat==0
    local m = r(mean)

    // Add footer stats
    qui estadd scalar cmean = `m'
    qui estadd local  pretreat "Yes"

    // Store & collect column title
    eststo
    local models  `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`short_title'""'
}

* --------- PRINT to Results window (captured in your .log) ----------
esttab `models', ///
    mtitle(`mlabels') ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableL1_pooled_restricted_completecases.csv", replace ///
    mtitle(`mlabels') ///
    keep(1.alltreat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment") ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    plain

*-----------------------------
* Table L1 (Table 19): Comparing Treatment Groups vs Placebo (missing==1)
*-----------------------------
capture erase "${table}/n_cate_treat_screen.tex"
capture erase "${table}/n_cate_treat_screen.csv"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutcome1 {

    * Column title (custom map -> var label -> var name)
    local short_title ""
    if ("`k'"=="zterrorism_regime")         local short_title "Dem. adv."
    if ("`k'"=="zgendemoc_post")            local short_title "Dem. pref."
    if ("`k'"=="zauth_support")             local short_title "Reject auth."
    if ("`k'"=="zdemoc_policy")             local short_title "Vote dem. cand."
    if ("`k'"=="zdonation")                 local short_title "Donate NGO"
    if ("`k'"=="zdemonstrat_democracy")     local short_title "Attend protest"
    if `"`short_title'"'=="" {
        local short_title : variable label `k'
        if `"`short_title'"'=="" local short_title "`k'"
    }

    * OLS with placebo base (0); restricted sample
    qui reg `k' ib0.treat $controls if missing==1 

    * Control Mean on the SAME estimation-sample placebo group
    quietly summarize `k' if e(sample) & treat==0
    local m = r(mean)

    * Joint equality: T1 = T2 = T3
    qui test (_b[1.treat] = _b[2.treat]) (_b[1.treat] = _b[3.treat])
    local p_all = r(p)

    * Footer stats
    qui estadd scalar cmean   = `m'
    qui estadd scalar p_all   = `p_all'
    qui estadd local  covars  "yes"

    eststo
    local models  `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`short_title'""'
}

* --------- PRINT to Results window (captured in .log) ----------
esttab `models', ///
    mtitle(`mlabels') ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    stats(N r2 covars cmean p_all, ///
          fmt(0 3 0 3 3) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" "All equal (p-val.)")) ///
    compress

* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableL2_compare_treatments_missing1.csv", replace ///
    mtitle(`mlabels') ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    stats(N r2 covars cmean p_all, ///
          fmt(0 3 0 3 3) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" "All equal (p-val.)")) ///
    plain
			
**-------------- Post video manipulation check ------------------
* Table M1 (Table 20): Treatment Effects — All Treatment Groups vs Placebo
**--------------------------------
capture erase "${table}/outc2_screen.tex"
capture erase "${table}/outc2_screen.csv"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutc_video {

  // Short DV titles (fits console)
    local short_title ""
    if "`k'"=="zvideo_infos_1" local short_title "Video info"
    if "`k'"=="zvideo_vicarious"    local short_title "Country vision"
    if "`k'"=="zvideo_social"  local short_title "Video sharing"
  
    if `"`short_title'"'=="" {
        local short_title : variable label `k'
        if `"`short_title'"'=="" local short_title "`k'"
    }

    * OLS (placebo=base), full controls
    qui reg `k' ib0.treat $controls 

    * Control Mean on estimation-sample placebo group
    quietly summarize `k' if e(sample) & treat==0
    local m = r(mean)

    * Joint equality: T1 = T2 = T3
    qui test (_b[1.treat]=_b[2.treat]) (_b[1.treat]=_b[3.treat])
    local p_all = r(p)

    * Footer stats
    qui estadd scalar cmean = `m'
    qui estadd scalar p_all = `p_all'
    qui estadd local  pretreat "yes"

    eststo
    local models  `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`short_title'""'
}

* --------- PRINT to Results window (captured in your .log) ----------
esttab `models', ///
    mtitle(`mlabels') ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableM1_postvideo_manipulation_alltreat_vs_placebo.csv", replace ///
    mtitle(`mlabels') ///
    keep(1.treat 2.treat 3.treat) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.treat "T1: Civic rights" ///
               2.treat "T2: General terrorism" ///
               3.treat "T3: Burkina Faso") ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    plain
		
// Heterogenous treatment effects

**--------------------------------
* Table M2 (Table 21): Treatment Effects: Pooled treatment versus Placebo
*Interaction with political interest: Removing political interest in the controls
global control female age ib1.reli_new ib1.ethnicity_new ib4.educ_new vote_intent  gendemoc_pre

*---------------------------------
* Pooled treatment × political interest (prints to Results)
*---------------------------------
capture erase "${table}/pooled_outc_screen.tex"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutc_video {

 // Short DV titles (fits console)
    local short_title ""
    if "`k'"=="zvideo_infos_1" local short_title "Video info"
    if "`k'"=="zvideo_vicarious"    local short_title "Country vision"
    if "`k'"=="zvideo_social"  local short_title "Video sharing"
  
    if `"`short_title'"'=="" {
        local short_title : variable label `k'
        if `"`short_title'"'=="" local short_title "`k'"
    }
    * OLS with interaction; placebo as base
    qui reg `k' ib0.alltreat##c.polint $control 

    * Control mean from the same estimation sample (placebo group)
    quietly summarize `k' if e(sample) & alltreat==0
    qui estadd scalar cmean = r(mean)
    qui estadd local  pretreat "yes"

    eststo
    local models  `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`short_title'""'
}

* ---- PRINT to Results window ----
esttab `models', ///
    mtitle(`mlabels') ///
    keep(1.alltreat polint 1.alltreat#c.polint) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment" ///
               polint     "Political interest" ///
               1.alltreat#c.polint "Treat × Pol. interest") ///
    stats(N r2 pretreat cmean, fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableM2_pooled_x_polinterest_postvideo.csv", replace ///
    mtitle(`mlabels') ///
    keep(1.alltreat polint 1.alltreat#c.polint) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat "Pooled treatment" ///
               polint     "Political interest" ///
               1.alltreat#c.polint "Treat × Pol. interest") ///
    stats(N r2 pretreat cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Pre-treatment" "Control Mean")) ///
    plain

*----------------------
* Table N1 (Table 22): Pooled effect — Interaction with distance to attacks
* Same format as other printed tables
*----------------------
capture erase "${table}/distance01_screen.tex"
capture erase "${table}/distance01_screen.csv"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutcome1 {

    * Short, readable column title (custom map -> var label -> var name)
    local t ""
    if ("`k'"=="zterrorism_regime")         local t "Dem. adv."
    if ("`k'"=="zgendemoc_post")            local t "Dem. pref."
    if ("`k'"=="zauth_support")             local t "Reject auth."
    if ("`k'"=="zdemoc_policy")             local t "Vote dem. cand."
    if ("`k'"=="zdonation")                 local t "Donate NGO"
    if ("`k'"=="zdemonstrat_democracy")     local t "Attend protest"
    if `"`t'"'=="" {
        local t : variable label `k'
        if `"`t'"'=="" local t "`k'"
    }

    * OLS with explicit bases: placebo (alltreat=0) & dist_1=0
    qui reg `k' ib0.alltreat##ib0.dist_1 $controls 

    * Control mean from the SAME estimation-sample placebo group
    quietly summarize `k' if e(sample) & alltreat==0
    qui estadd scalar cmean = r(mean)
    qui estadd local  covars "yes"

    * Joint test: the whole interaction block (alltreat × dist_1)
    qui testparm 1.alltreat##1.dist_1
    qui estadd scalar p_block = r(p)

    eststo
    local models  `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`t'""'
}

* ---- PRINT to Results window (captured in .log) ----
esttab `models', ///
    mtitle(`mlabels') ///
    keep(1.alltreat 1.dist_1 1.alltreat#1.dist_1) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat           "Pooled treatment" ///
               1.dist_1             "Near attack (50km)" ///
               1.alltreat#1.dist_1  "Treat × Near attack") ///
    stats(N r2 covars cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Covariates" "Control Mean")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableN1_pooled_x_distance50km.csv", replace ///
    mtitle(`mlabels') ///
    keep(1.alltreat 1.dist_1 1.alltreat#1.dist_1) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat           "Pooled treatment" ///
               1.dist_1             "Near attack (50km)" ///
               1.alltreat#1.dist_1  "Treat × Near attack") ///
    stats(N r2 covars cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" )) ///
    plain

*----------------------
* Table N2 (Table 23): Pooled effect: Interaction with community safety
*----------------------

capture erase "${table}/safe_comm_screen.tex"
capture erase "${table}/safe_comm_screen.csv"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutcome1 {

    * Short, readable column title (custom map -> var label -> var name)
    local t ""
    if ("`k'"=="zterrorism_regime")         local t "Dem. adv."
    if ("`k'"=="zgendemoc_post")            local t "Dem. pref."
    if ("`k'"=="zauth_support")             local t "Reject auth."
    if ("`k'"=="zdemoc_policy")             local t "Vote dem. cand."
    if ("`k'"=="zdonation")                 local t "Donate NGO"
    if ("`k'"=="zdemonstrat_democracy")     local t "Attend protest"
    if `"`t'"'=="" {
        local t : variable label `k'
        if `"`t'"'=="" local t "`k'"
    }

    * OLS with explicit base for treatment; continuous moderator
    qui reg `k' ib0.alltreat##c.safe_community $controls 

    * Control mean from SAME estimation-sample placebo group
    quietly summarize `k' if e(sample) & alltreat==0
    qui estadd scalar cmean = r(mean)
    qui estadd local  covars "yes"

    * Block test for interaction
    qui test 1.alltreat#c.safe_community
    qui estadd scalar p_block = r(p)

    eststo
    local models  `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`t'""'
}

* ---- PRINT to Results window (captured in .log) ----
esttab `models', ///
    mtitle(`mlabels') ///
    keep(1.alltreat safe_community 1.alltreat#c.safe_community) /// 
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat                  "Pooled treatment" ///
               safe_community              "Community safety" ///   
               1.alltreat#c.safe_community "Treat × Safety") ///
    stats(N r2 covars cmean p_block, ///
          fmt(0 3 0 3 3) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" "All (p-val.)")) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableN2_pooled_x_community_safety.csv", replace ///
    mtitle(`mlabels') ///
    keep(1.alltreat safe_community 1.alltreat#c.safe_community) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat                  "Pooled treatment" ///
               safe_community              "Community safety" ///
               1.alltreat#c.safe_community "Treat × Safety") ///
    stats(N r2 covars cmean p_block, ///
          fmt(0 3 0 3 3) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" "All (p-val.)")) ///
    plain

*----------------------
* Table N3 (Table 24): Pooled effect — Interaction with lived experience of terrorism
*----------------------

capture erase "${table}/terror_interact.xls"
capture erase "${table}/terror_interact.txt"
estimates clear
eststo clear

cap which esttab
if _rc ssc install estout, replace

local models
local mlabels

foreach k of varlist $zoutcome1 {

    * Short column titles (fallback to var label/name)
    local t ""
    if ("`k'"=="zterrorism_regime")         local t "Dem. adv."
    if ("`k'"=="zgendemoc_post")            local t "Dem. pref."
    if ("`k'"=="zauth_support")             local t "Reject auth."
    if ("`k'"=="zdemoc_policy")             local t "Vote dem. cand."
    if ("`k'"=="zdonation")                 local t "Donate NGO"
    if ("`k'"=="zdemonstrat_democracy")     local t "Attend protest"
    if `"`t'"'=="" {
        local t : variable label `k'
        if `"`t'"'=="" local t "`k'"
    }

    * OLS with explicit baselines: placebo (alltreat=0) and no lived exp (terror_exp=0)
    qui reg `k' ib0.alltreat##ib0.terror_exp $controls 

    * Control mean from SAME estimation-sample placebo group
    quietly summarize `k' if e(sample) & alltreat==0
    qui estadd scalar cmean = r(mean)
    qui estadd local  covars "yes"

    * Joint test for the interaction block
    qui testparm 1.alltreat##1.terror_exp
    qui estadd scalar p_block = r(p)

    eststo
    local models  `"`models' `e(name)'"'
    local mlabels `"`mlabels' "`t'""'
}

* ---- PRINT to Results window (captured in .log) ----
esttab `models', ///
    mtitle(`mlabels') ///
    keep(1.alltreat 1.terror_exp 1.alltreat#1.terror_exp) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat                 "Pooled treatment" ///
               1.terror_exp               "Lived terror exp." ///
               1.alltreat#1.terror_exp    "Treat × Lived exp.") ///
    stats(N r2 covars cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" )) ///
    compress
* ---------------- SAVE TO output/tables (CSV only) ----------------
local tdir = subinstr("${table}","\","/",.)
if substr("`tdir'", -1, 1) != "/" local tdir "`tdir'/"

esttab `models' using "`tdir'TableN3_pooled_x_lived_terror_experience.csv", replace ///
    mtitle(`mlabels') ///
    keep(1.alltreat 1.terror_exp 1.alltreat#1.terror_exp) ///
    b(3) se level(95) brackets ///
    star(* 0.05) ///
    label nonotes noobs nobaselevels ///
    coeflabels(1.alltreat              "Pooled treatment" ///
               1.terror_exp            "Lived terror exp." ///
               1.alltreat#1.terror_exp "Treat × Lived exp.") ///
    stats(N r2 covars cmean, ///
          fmt(0 3 0 3) ///
          labels("Observations" "R^2" "Covariates" "Control Mean" )) ///
    plain
			
*--------------------------------------------------------------------
*APPENDIX FIGURES
*--------------------------------------------------------------------
*-----------------------------
* Figure N1 (Figure 9): Marginal effects of the democratic promotion treatment 
* on outcomes by e, where (0) = not at all safe; (10) = very safe
*-----------------------------
global controls female age ib1.reli_new ib1.ethnicity_new ib4.educ_new vote_intent polint gendemoc_pre


foreach k of varlist $zoutcome1 {
    
    * Assign descriptive title from label
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    * Regression model with interaction
    qui reg `k' i.alltreat##c.safe_community $controls 

    * Marginal effects at varying safety levels
    qui margins, dydx(alltreat) at(safe_community = (0(1)10)) 

    * Plot margins
    qui marginsplot, ///
        ylabel(-.15(.05).15) ///
        xlabel(, labsize(medium)) ///
        yline(0) ///
        xtitle("Safety in the community", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(medsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

* Combine plots
graph combine $zoutcome1
graph save "${graph}/safety.gph", replace 
graph export "${graph}/safety.eps", replace 
graph export "${graph}/safety.pdf", as(pdf) replace

*-----------------------------
* Figure N2 (Figure 10): Marginal effects: *Regression using non-linear distance
*-----------------------------

foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    // Regression with quadratic distance interacted with treatment
    qui reg `k' i.alltreat##c.km_to_id_B##c.km_to_id_B $controls 

    // Marginal effects of treatment over distance (0 to 120km by 10)
    qui margins, dydx(alltreat) at(km_to_id_B = (0(10)120))

    // Plot
    qui marginsplot, ///
        ylabel(-.25(.05).25) ///
        xlabel(, labsize(vsmall)) ///
        yline(0) ///
        xtitle("Distance to terrorist attacks (km)", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(medsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/distance2.gph", replace
graph export "${graph}/distance2.eps", replace
graph export "${graph}/distance2.pdf", as(pdf) replace

// Individual treatments

codebook treat
recode treat (0=0)(1=1)(2 3=.), ge(right_P)
recode treat (0=0)(2=1)(1 3=.), ge(general_P)
recode treat (0=0)(3=1)(1 2=.), ge(BFaso_P)

ta treat right_P
ta treat general_P
ta treat BFaso_P
**--------------------------------
* Figure N3 (Figure 11): Marginal effects: by Lived experience (Civic right vs placebo)
**--------------------------------
foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    qui reg `k' i.right_P##i.terror_exp $controls 
    qui margins, dydx(right_P) at(terror_exp=(0(1)1))

    qui marginsplot, ///
        ylabel(-.15(.05).15) ///
        xlabel(, labsize(medium)) ///
        yline(0) ///
        xtitle("Terrorism experience", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/terror_exp1.gph", replace
graph export "${graph}/terror_exp1.eps", replace
graph export "${graph}/terror_exp1.pdf", as(pdf) replace

**--------------------------------
* Figure N4 (Figure 12): Marginal effects:Proximity to terrorist attacks (Civic vs placebo)
**--------------------------------
 foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    qui reg `k' i.right_P##c.km_to_id_B $controls 
    qui margins, dydx(right_P) at(km_to_id_B=(0(20)200))

    qui marginsplot, ///
        ylabel(-.15(.05).15) ///
        xlabel(, labsize(small)) ///
        yline(0) ///
        xtitle("Distance to terrorist attacks (km)", size(small)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/km1.gph", replace 
graph export "${graph}/km1.eps", replace 
graph export "${graph}/km1.pdf", as(pdf) replace

**--------------------------------
*  Figure N5 (Figure 13): Marginal effects:: by Lived experience (general vs placebo)
**--------------------------------
foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    qui reg `k' i.general_P##i.terror_exp $controls 
    qui margins, dydx(general_P) at(terror_exp=(0(1)1))

    qui marginsplot, ///
        ylabel(-.15(.05).15) ///
        xlabel(, labsize(medium)) ///
        yline(0) ///
        xtitle("terrorism experience", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/terror_exp2.gph", replace 
graph export "${graph}/terror_exp2.eps", replace 
graph export "${graph}/terror_exp.pdf", as(pdf) replace

**--------------------------------
* Figure N6 (Figure 14): Marginal effects:Proximity to terrorist attacks (general vs placebo)
**--------------------------------

foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    qui reg `k' i.general_P##c.km_to_id_B $controls 
    qui margins, dydx(general_P) at(km_to_id_B=(0(20)200))

    qui marginsplot, ///
        ylabel(-.15(.05).15) ///
        xlabel(, labsize(small)) ///
        yline(0) ///
        xtitle("Distance to terrorist attacks (km)", size(small)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/km2.gph", replace 
graph export "${graph}/km2.eps", replace 
graph export "${graph}/km2.pdf", as(pdf) replace


**--------------------------------
*  Figure N7 (Figure 15): Marginal effects:: by Lived experience (Burkina vs placebo)
**--------------------------------
foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    qui reg `k' i.BFaso_P##i.terror_exp $controls 
    qui margins, dydx(BFaso_P) at(terror_exp=(0(1)1))

    qui marginsplot, ///
        ylabel(-.15(.05).15) ///
        xlabel(, labsize(small)) ///
        yline(0) ///
        xtitle("terrorism experience", size(small)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/terror_exp3.gph", replace 
graph export "${graph}/terror_exp3.eps", replace 
graph export "${graph}/terror_exp.pdf", as(pdf) replace

**--------------------------------
*  Figure N8 (Figure 16): Marginal effects:Proximity to terrorist attacks (Burkina vs placebo)
**--------------------------------

foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    qui reg `k' i.BFaso_P##c.km_to_id_B $controls 
    qui margins, dydx(BFaso_P) at(km_to_id_B=(0(20)200))

    qui marginsplot, ///
        ylabel(-.15(.05).15) ///
        xlabel(, labsize(small)) ///
        yline(0) ///
        xtitle("Distance to terrorist attacks (km)", size(small)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/km3.gph", replace 
graph export "${graph}/km3.eps", replace 
graph export "${graph}/km3.pdf", as(pdf) replace


// Conditional effect: Level of Education

**--------------------------------
*  Figure N9 (Figure 17): Marginal effects:Civic vs placebo
**--------------------------------
*Removing education from pre-treatment
global control_educ female age ib1.reli_new ib1.ethnicity_new ib4.educ_new vote_intent polint gendemoc_pre

 foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    qui reg `k' i.right_P##i.educ_new $control_educ 
    qui margins, dydx(right_P) at(educ_new=(1(1)4))

    qui marginsplot, ///
        ylabel(-.7(.2).7) ///
        xlabel(, labsize(small)) ///
        yline(0) ///
      xtitle(" Level of Education", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.6) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/educ_right.gph", replace 
graph export "${graph}/educ_right.eps", replace 
graph export "${graph}/educ_right.pdf", as(pdf) replace


**--------------------------------
*  Figure N10 (Figure 18): Marginal effects:: General vs placebo
**--------------------------------
foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    qui reg `k' i.general_P##i.educ_new $control_educ 
    qui margins, dydx(general_P) at(educ_new=(1(1)4))

    qui marginsplot, ///
        ylabel(-.7(.2).7) ///
        xlabel(, labsize(small)) ///
        yline(0) ///
        xtitle(" Level of Education", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.6) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/educ_general.gph", replace 
graph export "${graph}/educ_general.eps", replace 
graph export "${graph}/educ_general.pdf", as(pdf) replace

**--------------------------------
*  Figure N11 (Figure 19): Marginal effects:Proximity to terrorist attacks (Burkina vs placebo)
**--------------------------------

foreach k of varlist $zoutcome1  {

    // Human-readable DV title
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    qui reg `k' i.BFaso_P##i.educ_new $control_educ 
    qui margins, dydx(BFaso_P) at(educ_new=(1(1)4))

    qui marginsplot, ///
        ylabel(-.7(.2).7) ///
        xlabel(, labsize(medium)) ///
        yline(0) ///
        xtitle(" Level of Education", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.6) legend(off)
}

graph combine $zoutcome1
graph save "${graph}/educ_BF.gph", replace 
graph export "${graph}/educ_BF.eps", replace 
graph export "${graph}/educ_BF.pdf", as(pdf) replace

// Emotions

*--------------------------------
*  Figure O1 (Figure 20): Marginal effects of democratic promotion treatment 
* by anger traits (0 = not at all angry; 10 = very angry)
*--------------------------------

foreach k of varlist $zoutcome1 {
    
    * Assign descriptive label for DV
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    * Interaction regression
    qui reg `k' i.alltreat##c.anger_traits $controls 
    * Marginal effects
    qui margins, dydx(alltreat) at(anger_traits = (0(1)10)) 

    * Plot
    qui marginsplot, ///
        ylabel(-0.15(.05)0.15) ///
        xlabel(, labsize(medium)) ///
        yline(0) ///
        xtitle("Anger", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(small)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

* Combine and export
graph combine $zoutcome1 
graph save "${graph}/anger_traits.gph", replace 
graph export "${graph}/anger_traits.eps", replace 
graph export "${graph}/anger_traits.pdf", as(pdf) replace

*--------------------------------
* Figure O2 (Figure 21): Marginal effects of democratic promotion treatment 
* by anxiety traits (0 = not at all anxious; 10 = very anxious)
*--------------------------------

foreach k of varlist $zoutcome1 {
    
    * Assign descriptive label for DV
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    * Interaction regression
    qui reg `k' i.alltreat##c.anxiety_traits $controls 

    * Marginal effects
    qui margins, dydx(alltreat) at(anxiety_traits = (0(1)10)) 

    * Plot
    qui marginsplot, ///
        ylabel(-0.15(.05)0.15) ///
        xlabel(, labsize(medium)) ///
        yline(0) ///
        xtitle("Anxiety", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(small)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

* Combine and export
graph combine $zoutcome1 
graph save "${graph}/anxiety_traits.gph", replace 
graph export "${graph}/anxiety_traits.eps", replace 
graph export "${graph}/anxiety_traits.pdf", as(pdf) replace

*--------------------------------
* Figure O3 (Figure 22): Marginal effects of democratic promotion treatment 
* by optimism traits (0 = not at all optimistic; 10 = very optimistic)
*--------------------------------

foreach k of varlist $zoutcome1 {

    * Assign descriptive label for DV
    local title_label ""
    if "`k'" == "zterrorism_regime"         local title_label "Democratic advantage"
    if "`k'" == "zgendemoc_post"            local title_label "Democratic preference"
    if "`k'" == "zauth_support"             local title_label "Rejection of authoritarianism"
    if "`k'" == "zdemoc_policy"             local title_label "Vote for democratic candidate"
    if "`k'" == "zdonation"                 local title_label "Donate to pro-democratic NGO"
    if "`k'" == "zdemonstrat_democracy"     local title_label "Participation in pro-democratic protest"

    * Interaction regression
    qui reg `k' i.alltreat##c.optimism_traits $controls 

    * Marginal effects
    qui margins, dydx(alltreat) at(optimism_traits = (0(1)10)) 

    * Plot
   qui marginsplot, ///
        ylabel(-0.15(.05)0.15) ///
        xlabel(, labsize(medium)) ///
        yline(0) ///
        xtitle("Optimism", size(medium)) ///
        ytitle("Effects of treatments on outcome", size(vsmall)) ///
        title("DV: `title_label'", size(medium)) ///
        name(`k', replace) ///
        recastci(rspike) recast(scatter) scale(.8) legend(off)
}

* Combine and export
graph combine $zoutcome1		
graph save "${graph}/optimism_traits.gph", replace 
graph export "${graph}/optimism_traits.eps", replace 
graph export "${graph}/optimism_traits.pdf", as(pdf) replace

	
**--------------------------------
* Mediation Analysis
**--------------------------------

*codebook treat 
recode treat(1 3 =.)(2=1) (0=0), ge(terror_G)
label var terror_G "Terrorism general"
ta terror_G treat

global meddep zgendemoc_post zauth_support zdemoc_policy zdonation zdemonstrat_democracy 

capture erase "${table}/med1.xls"
capture erase "${table}/med1.txt"
estimates clear

**--------------------------------
* Table P1 (Table 25): Mediation results for Democratic preference
**--------------------------------
 medeff (regress  zterrorism_regime terror_G) (regress  zgendemoc_post terror_G zterrorism_regime $medcontrols),  treat(terror_G) mediate(zterrorism_regime) 
**--------------------------------
*Table P2 (Table 26): Mediation results for Participation in pro-democratic protest
**--------------------------------
medeff (regress  zterrorism_regime terror_G) (regress  zdemonstrat_democracy terror_G zterrorism_regime $medcontrols), treat(terror_G) mediate(zterrorism_regime)
**--------------------------------
* Table P3 (Table 27): Mediation results for Donation for pro-Democratic NGO
**--------------------------------
medeff (regress  zterrorism_regime terror_G) (regress  zdonation terror_G zterrorism_regime $medcontrols), treat(terror_G) mediate(zterrorism_regime)

capture noisily log close rep
***--------------------------------END **--------------------------------

